package com.wmh.baseservice.skd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wmh.baseservice.skd.pojo.SkdLeaderInfo;
import com.wmh.baseservice.skd.pojo.vo.FollowGroupNumAndBrowseNumRespVO;
import com.wmh.baseservice.skd.service.SkdLeaderInfoService;
import com.wmh.baseservice.skd.mapper.SkdLeaderInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author CH
* @description 针对表【skd_agent_info】的数据库操作Service实现
* @createDate 2023-12-10 17:50:02
*/
@Service
public class SkdLeaderInfoServiceImpl extends ServiceImpl<SkdLeaderInfoMapper, SkdLeaderInfo>
    implements SkdLeaderInfoService {

    @Resource
    private SkdLeaderInfoMapper skdLeaderInfoMapper;

    @Override
    public SkdLeaderInfo getLeaderInfoByGroupBuyingActivityId(Long goodsId) {
        return skdLeaderInfoMapper.selectByGroupBuyingActivityId(goodsId);
    }

    @Override
    public Integer getGroupNoById(Long leaderId) {
        return skdLeaderInfoMapper.getGroupNoNyId(leaderId);
    }

    @Override
    public List<SkdLeaderInfo> getLeaderInfoListByUsId(Long usId) {
        return skdLeaderInfoMapper.selectList(new QueryWrapper<SkdLeaderInfo>().eq("us_id", usId));
    }

    /**
     * 根据团购活动id查询跟团人数和浏览人数
     * @param id 团购活动id
     * @return 返回跟团人数和浏览人数团信息响应体
     */
    @Override
    public FollowGroupNumAndBrowseNumRespVO getFollowGroupNumAndBrowseNumByGroupBuyingActivityId(Long id) {
        return skdLeaderInfoMapper.selectFollowGroupNumAndBrowseNumByGroupBuyingActivityId(id);
    }

    /**
     * 根据跟团人数倒序获取团信息列表
     * @return 返回团购活动id和跟团人数信息
     */
    @Override
    public List<SkdLeaderInfo> querySkdLeaderInfoByFollowGroupNumDesc() {
        QueryWrapper<SkdLeaderInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("group_buying_activity_id", "follow_group_num", "browse_num")
                .eq("deleted", 0)
                .orderByDesc("follow_group_num");

        return skdLeaderInfoMapper.selectList(queryWrapper);
    }

    /**
     * 恢复(已删除)团信息
     * @param id 团id
     * @return 返回是否恢复成功
     */
    @Override
    public boolean recover(Long id) {
        return skdLeaderInfoMapper.recover(id);
    }
}